<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>广告管理</title>
<meta name="decorator" content="default" />

<script type="text/javascript">
	$(document).ready(function() {
		$("#name").focus();
		$("#inputForm").validate();
		//校验结束时间必须大于初始时间
		$.validator.addMethod("compareDate",function(value,element){
	        var assigntime = $("#startTime").val();
	        var deadlinetime = $("#endTime").val();
	        var reg = new RegExp('-','g');
	        assigntime = assigntime.replace(reg,'/');//正则替换
	        deadlinetime = deadlinetime.replace(reg,'/');
	        assigntime = new Date(parseInt(Date.parse(assigntime),10));
	        deadlinetime = new Date(parseInt(Date.parse(deadlinetime),10));
	        if(assigntime>deadlinetime){
	            return false;
	        }else{
	            return true;
	        }
	    },"<font color='#E47068'>结束日期必须大于开始日期</font>");
	});

	function spaceChange() {
		var spaceid = $("#space").val();
		<c:forEach items="${spacels}" var="space">
		var spaceid2 = "${space.id}";
		if(spaceid==spaceid2){
		<c:if test="${space.adType eq 'imag'}">
		$("#flashdiv").hide();
		$("#imagdiv").show();
		</c:if>
		<c:if test="${space.adType eq 'flash'}">
		$("#flashdiv").show();
		$("#imagdiv").hide();
		</c:if>
		<c:if test="${space.adType eq 'word'}">
		</c:if>
		return;
		}
		</c:forEach>
	}
	
	//上传标题图片
	function uploadFlash() {

		var mf = $("#flashfile");
		//检查是否选择了文件
		if (mf.val() == "") {
			$.jBox.info('没有选择上传文件');
			<%--$.alert("提示",
					"没有选择上传文件");--%>
			return;
		}

		//复制一个file放至原处
		$("#tuploaddiv").append(mf.clone().attr('value', ''));
	
		//修改属性
		mf.attr("id", "");
		//将file移动至上传表单
		$("#flashUpload").empty();
		$("#flashUpload").append(mf);
		
		//其他表单
		$("#coldflashPath").val($("#oldflashPath").val());
		$("#flashUploadForm").submit();
	}
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/ad/adver/list">广告列表</a></li>
		
		<li class="active"><a href="${ctx}/ad/adver/form?id=${advertisement.id}">广告添加</a></li>
	</ul>
	<br/>

	<form:form id="inputForm" modelAttribute="advertisement" action="${ctx}/ad/adver/save" method="post"
		class="form-horizontal">
		<form:hidden path="id" />
		<tags:message content="${message}" />
		<div class="control-group">
			<label class="control-label" for="space"><span style="color:red">*</span>广告位:</label>
			<div class="controls">
				<form:select id="space" path="spaceId" items="${spacels}" itemLabel="name" itemValue="id" class="required"
					onchange="spaceChange()" />
			</div>
		</div>
	<div class="control-group">
			<label class="control-label" for="name"><span style="color:red">*</span>广告名:</label>
			<div class="controls">
				<form:input path="name"  htmlEscape="false" maxlength="100"  class="required"/>
			</div>
		</div>
		
		<div class="control-group" id="imagdiv" style="">
			<label class="control-label" for="adconPath"><span style="color:red">*</span>广告图片:</label>
			<div class="controls">
				路径:
				<form:input id="adconPath" path="adconPath" name="adconPath"
					htmlEscape="false" maxlength="255"  class="required" />
				<tags:ckfinder input="adconPath" type="image" uploadPath=""
					selectMultiple="false" />
					*广告位广告类型为图片
			</div>
			       
			
		</div>

<%-- 		<div class="control-group" id="flashdiv" style="<c:if test="${advertisement.space.adType ne 'flash'}">display: none</c:if>"> --%>
<!-- 			<label class="control-label" for="flashPath">广告视频:</label> -->
<!-- 			<div class="controls"> -->
<%-- 				<input type="hidden" id="oldflashPath" value="${infoMain.flashPath}" /> --%>
<%-- 				<form:input path="flashPath" id="flashPath" name="flashPath" --%>
<%-- 					htmlEscape="false" maxlength="255" class="input-xlarge"/> --%>
<!-- 			</div> -->
<!-- 			<div class="controls"> -->
<!-- 				<span id="tuploaddiv"> <input id="flashfile" name="flashfile" -->
<!-- 					type="file" size="14" /> -->
<!-- 				</span> <input type="button" value="上传" onclick="uploadFlash()" /> -->
<!-- 				*广告位广告类型为视频 -->
<!-- 			</div> -->
<!-- 		</div> -->
		
		<div class="control-group">
			<label class="control-label" for="url">链接地址:</label>
			<div class="controls">
				<form:input path="url" htmlEscape="false" maxlength="255"
					 />
				<span class="help-inline"> 例:http://www.baidu.com</span>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label" for="content">文字内容:</label>
			<div class="controls">
				<form:textarea path="content" htmlEscape="false" rows="4"
					maxlength="255" class="input-xxlarge" />
			</div>
		</div>

		<div class="control-group">
			<label class="control-label" for="clickCount">点击数/展示数:</label>
			<div class="controls">
				<form:input path="clickCount" style="width:60px" htmlEscape="false"
					maxlength="10"  class="digits" />
				/
				<form:input path="displayCount" style="width:60px"
					htmlEscape="false" maxlength="10"   class="digits" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="startTime">有效期:</label> 从 <input
				id="startTime" name="startTime" type="text" readonly="readonly"
				maxlength="20" class="input-medium Wdate"
				value="<fmt:formatDate value="${advertisement.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});" />
			到 <input id="endTime" name="endTime" type="text" readonly="readonly"
				maxlength="20" class="input-medium Wdate compareDate"
				value="<fmt:formatDate  value="${advertisement.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});" />
		</div>

		<div class="control-group">
			<label class="control-label" for="orderId">排序:</label>
			<div class="controls">
				<form:input path="orderId" style="width:60px" htmlEscape="false"
					maxlength="10"  class="digits"/>
				<span class="help-inline">只能是数字，由大到小排序</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="isEnable">是否启用:</label>
			<div class="controls">

				<form:radiobutton path="isEnable" value="1" />
				是
				<form:radiobutton path="isEnable" value="0" />
				否
			</div>
		</div>


		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存" />&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)" />
		</div>
	</form:form>
	
	<form id="flashUploadForm" name="flashUploadForm" action="${ctx}/ad/adver/flashUpload" method="post"	enctype="multipart/form-data" target="image_iframe"
		style="display: none; width: 0px; height: 0px;">
		<span id="flashUpload"></span> 
		<input type="hidden" id="coldflashPath" name="coldflashPath" />
	 </form>
	  <iframe name="image_iframe" frameborder="0" border="0" style="display:false; width: 0px; height: 0px;"></iframe>
</body>
</html>

